import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
from Logic.open_file import read_text_file
from Logic.create_csv_in_selected_folder import create_csv
def history_upload():
    text_data = read_text_file('history.txt')

    # 创建Tkinter根窗口
    root = tk.Tk()
    root.withdraw()  # 隐藏主窗口

    # 让用户选择文件夹
    folder_path = filedialog.askdirectory(title="Please select a folder")
    if not folder_path:
        messagebox.showwarning("Tip", "Please select a folder!")
        return

    # 指定CSV文件名
    csv_filename = "history.csv"

    # 在用户选择的文件夹中创建CSV文件并写入数据
    create_csv(text_data, folder_path, csv_filename)





